package com.wechat.core.exception;

import com.wechat.core.bean.Result;
import com.wechat.core.constant.enums.support.RStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
public final class NotLoginException extends RuntimeException {
    private static final long serialVersionUID = -1L;

    private Object data;

    private int code = RStatus.FAIL.getValue();

    public NotLoginException() {
        super("未登录");
    }

    public NotLoginException(String message) {
        super(message);
    }

    public NotLoginException(String message, int code) {
        super(message);
        this.code = code;
    }

    public NotLoginException(String message, Object data) {
        super(message);
        if(data instanceof RStatus){
            RStatus status = (RStatus) data;
            this.code = status.getValue();
        }
        this.data = data;
    }

    public NotLoginException(String message, Object data, int code) {
        super(message);
        this.data = data;
        this.code = code;
    }

    public NotLoginException(Result result) {
        super(result.getMessage());
        this.data = result.getResult();
        this.code = result.getCode();
    }

    public NotLoginException(Throwable cause) {
        super(cause);
    }

    public NotLoginException(String message, Throwable cause) {
        super(message, cause);
    }

    public NotLoginException(String message, Object data, Throwable cause) {
        super(message, cause);
        this.data = data;
    }

    @Override
    public String toString() {
        return "NotLoginException{" +
                "data=" + data +
                ", code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
